from rest_framework import serializers
from tools.models import Event,Fault,Remind
from user.serializers import UserSerializer

class EventSerializer(serializers.ModelSerializer):

    user = UserSerializer(many=True, read_only=True)
    start_time = serializers.DateTimeField(format="%Y-%m-%d %H:%M:%S", required=False)
    end_time = serializers.DateTimeField(format="%Y-%m-%d %H:%M:%S", required=False)
    create_time = serializers.DateTimeField(format="%Y-%m-%d %H:%M:%S", required=False, read_only=True)
    class Meta:
        model = Event
        fields = "__all__"
        read_only_fields = ("id",) # 仅用于序列化（只读）字段，反序列化（更新）可不传

class FaultSerializer(serializers.ModelSerializer):

    user = UserSerializer(many=True, read_only=True)
    start_time = serializers.DateTimeField(format="%Y-%m-%d %H:%M:%S", required=False)
    end_time = serializers.DateTimeField(format="%Y-%m-%d %H:%M:%S", required=False)
    create_time = serializers.DateTimeField(format="%Y-%m-%d %H:%M:%S", required=False, read_only=True)
    class Meta:
        model = Fault
        fields = "__all__"
        read_only_fields = ("id",) # 仅用于序列化（只读）字段，反序列化（更新）可不传


class RemindSerializer(serializers.ModelSerializer):

    user = UserSerializer(many=True, read_only=True)
    last_datetime = serializers.DateTimeField(format="%Y-%m-%d %H:%M:%S", required=False)
    create_time = serializers.DateTimeField(format="%Y-%m-%d %H:%M:%S", required=False, read_only=True)
    class Meta:
        model = Remind
        fields = "__all__"
        read_only_fields = ("id",) # 仅用于序列化（只读）字段，反序列化（更新）可不传